package mbms.mobilebudget.manager;


import java.sql.SQLException;

import com.j256.ormlite.android.apptools.OrmLiteBaseActivity;
import com.j256.ormlite.android.apptools.OrmLiteBaseService;
import com.j256.ormlite.dao.Dao;
import com.j256.ormlite.dao.RuntimeExceptionDao;

import android.content.Context;
import android.content.Intent;
import android.os.IBinder;
import mbms.mobilebudget.database.DatabaseHandler;
import mbms.mobilebudget.entity.User;

public class LoginManager extends OrmLiteBaseActivity<DatabaseHandler>{


	/*public User loginUser(User loggingUser, DatabaseHandler dbs) {
		return dbs.loginUser(loggingUser);
		
	}/*/
	
	public User registerUser(User registerUser, String msg) throws SQLException{
		//RuntimeExceptionDao<SimpleData, Integer> simpleDao = getHelper().getSimpleDataDao();
		if(mandatoryCheckUser(registerUser, msg)){
			Dao<User, Integer> userDao = getHelper().getUserDao();
			userDao.create(registerUser);
			msg= "User registered";
			return registerUser;
		}
		else {
			msg = "Problem in registration";
			return null;
		}
			
	}
	private boolean mandatoryCheckUser(User user, String msg){
		if(user == null || user.getCommEmailAddress().equals("")| user.getFirstName().equals("") || user.getLastName().equals("") || 
				user.getPassword().equals("") || user.getSequrityQuestion().equals("")  ||
				user.getSequrityQuestionAnswer().equals("")|| user.getUsername().equals("")){
			msg = "All fields must be filled";
			return false;
		}
		else
			return true;
	}

}
